Use with Toolbar Component
In Scripting, views can populate their navigation bar or toolbar area using either the original ToolBarProps object or the declarative component-based API that mirrors SwiftUI’s toolbar system. This document explains in detail how to use the Toolbar, ToolbarItem, ToolbarItemGroup, ToolbarSpacer, and DefaultToolbarItem components, including parameters, types, and usage patterns.
Overview
The toolbar property can be used in two ways:
- By passing a
ToolBarPropsobject - By passing a VirtualNode, which must be a
<Toolbar>component
When using the component-based API, all toolbar content is declared inside a <Toolbar> container, and each item defines its placement explicitly. This provides clearer structure and more precise layout control, similar to SwiftUI.
Toolbar
The <Toolbar> component serves as a container for toolbar content. It does not define placement itself; instead, ToolbarItem and ToolbarItemGroup determine where items go.
Example
ToolbarItem
ToolbarItem represents a single toolbar element placed at a specific position.
Parameters
Example
ToolbarItemGroup
ToolbarItemGroup allows multiple toolbar items to be grouped together in a single placement.
Parameters
Example
ToolbarSpacer
ToolbarSpacer inserts empty space in a toolbar. It can be used to fine-tune layout between items.
Parameters
Behavior
flexible: Expands to fill available space.fixed: Adds a fixed separation between items.
Example
DefaultToolbarItem
DefaultToolbarItem inserts system-provided toolbar items, such as the sidebar toggle button or search button.
Parameters
Example
Complete Example
Relationship with ToolBarProps
Both approaches remain fully supported. When a VirtualNode is passed, it must be a <Toolbar> component to ensure proper layout interpretation.
